package com.tzbank.wisdom.controller;

import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
 * 	 记账信息控制器
 * @author tzbank
 *
 */

import com.tzbank.entity.Charge;
import com.tzbank.utils.CodeUtil;
import com.tzbank.utils.ResultUtil;
import com.tzbank.wisdom.service.ChargeService;
@RestController
@RequestMapping("charge")
public class ChargeController {
	
	@Autowired
	private ChargeService chargeService;

	/**
	 * 查询记账信息
	 * @param charge
	 * @return
	 */
	@PostMapping("getChargeInfo")
	public Map<String,Object> getCharge(@RequestBody Charge charge) {
		return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), chargeService.getCharge(charge));
	}
	
	/**
	 * 添加或修改记账信息
	 * 
	 * @param charge
	 * @return
	 */
	@PostMapping("updateOrSaveCharge")
	public Map<String,Object> updateOrSaveCharge(@RequestBody Charge charge){
		
		if(charge==null) {
			return ResultUtil.resultMap(CodeUtil.CODE_10000.getName(), CodeUtil.CODE_10000.getCode(), null);
		}else if (StringUtils.isEmpty(charge.getComment())|| StringUtils.isEmpty(charge.getTellSeqNo())
				|| StringUtils.isEmpty(charge.getOriTranDate())) {
			return ResultUtil.resultMap(CodeUtil.CODE_10000.getName(), CodeUtil.CODE_10000.getCode(), null);
		}
		
		return chargeService.updateCharge(charge);
	}
	
	/**
	 * 获取标签内容
	 * 
	 * @param charge
	 * @return
	 */
	@PostMapping("getLable")
	public Map<String,Object> getLable(){
		return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), chargeService.getLable());
	}
	
	//
}
